package com.lanou.elh.sysmanage.item_manage.web.controller;

import com.lanou.elh.sysmanage.item_manage.entity.ItemCat;
import com.lanou.elh.sysmanage.item_manage.service.ItemCatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(description = "商品分类信息")
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;

    @GetMapping("/item/cat/list")
    @ApiOperation(value = "通过父id获取商品分类列表")
    public List<ItemCat> getItemCartList(@RequestParam(value = "id", defaultValue = "0") Integer pId) {
        List<ItemCat> list = itemCatService.getItemCartList(pId);
        return list;
    }


    @PostMapping("/item/cat/add")
    @ApiOperation(value = "添加商品分类")
    public boolean addItemCategory(ItemCat itemCat) {
        return itemCatService.addItemCategory(itemCat);
    }

    @PostMapping("/item/cat/update")
    @ApiOperation(value = "编辑商品分类")
    public boolean updateItemCategory(ItemCat itemCat) {
        return itemCatService.updateItemCategory(itemCat);
    }

    @DeleteMapping("/item/cat/delete/{id}")
    @ApiOperation("删除商品分类")
    public boolean deleteItemCategory(@PathVariable Long id) {
        return itemCatService.deleteItemCat(id);
    }
}
